namespace LanSunERP
{
    using System;
    using System.ServiceModel;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Runtime.Serialization;
    using System.Collections;
    using System.Data;
    using System.Data.SqlClient;

    public class TableList : QueryCommand
    {
        public TableList() : base() { }
        public TableList(SqlCommand cmdSQL, DataTable dtRequest, string RequestJob)
            : base(cmdSQL, dtRequest, RequestJob) { }
        public SqlCommand BuildCommand()
        {

            switch (RequestJob.Substring(6, 10))
            {
                case "0000000000":
                    /*
                         case "TableList":
                            TableList m_TableList = new TableList(cmdSQL, dtRequest, RequestJob);
                            cmdSQL = m_TableList.BuildCommand();
                            break;
                    */
                    break;
                case "1000000000":
                    break;
                case "2000000001":
                case "4000000000":
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    break;
                case "1000006802":  //IX_GoodsTypeKeyDef
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    break;
                case "1000006798":  //IX_TableList
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));
                    break;
                case "1000006801":  //IX_TableList_GoodsTypeKeyDefKey
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    break;
                case "1000006800":  //IX_TableList_Key
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));
                    break;
                case "1000006803":  //IX_TableList_MasterKey
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));
                    break;
                case "1000006799":  //IX_TableList_Parent
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));
                    break;
                case "1000006805":  //IX_TableList_SysID
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    break;
                case "1000006806":  //IX_TableList_UGoodsKey
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@UGoodsKey", dwRequest["UGoodsKey"].ToString()));
                    break;
                case "1000006807":  //TX_TableList
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    break;
                case "2000000000":
                case "3000000001":
                case "3000000000":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    cmdSQL = BuildInstanceKey(cmdSQL, dwRequest);
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@UGoodsKey", dwRequest["UGoodsKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TableID", dwRequest["TableID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TableName", dwRequest["TableName"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ShortName", dwRequest["ShortName"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@SubStatus", dwRequest["SubStatus"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyCondition", dwRequest["KeyCondition"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TableGroup", dwRequest["TableGroup"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TableClass", dwRequest["TableClass"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Status", dwRequest["Status"].ToString()));
                    break;
            }
            return cmdSQL;

        }
        public override SqlCommand BuildInstanceKey(SqlCommand cmdSQL, DataRow dwTemp)
        {
            string InstanceKey = dwTemp["InstanceKey"].ToString().Trim();
            string SysID = dwTemp["SysID"].ToString().Trim();
            string KeyDefType = dwTemp["KeyDefType"].ToString().Trim();
            string GoodsTypeKey = dwTemp["GoodsTypeKey"].ToString().Trim();
            string GoodsTypeKeyDefKey = dwTemp["GoodsTypeKeyDefKey"].ToString().Trim();
            string GoodsKey = dwTemp["GoodsKey"].ToString().Trim();

            {
                if (SysID != "" && KeyDefType != "" && GoodsTypeKey != "" && GoodsTypeKeyDefKey != "" && GoodsKey != "")
                {
                    InstanceKey = SysID + "." + KeyDefType + "." + GoodsTypeKey + "." + GoodsTypeKeyDefKey + "." + GoodsKey;
                    dwTemp["InstanceKey"] = InstanceKey;
                    dwTemp.AcceptChanges();
                }
            }
            cmdSQL.Parameters.Add(new SqlParameter("@InstanceKey", dwRequest["InstanceKey"].ToString()));
            return base.BuildInstanceKey(cmdSQL, dwTemp);
        }
    }
    public class TableListQueryCond : QueryCommand
    {
        public TableListQueryCond() : base() { }
        public TableListQueryCond(SqlCommand cmdSQL, DataTable dtRequest, string RequestJob)
            : base(cmdSQL, dtRequest, RequestJob) { }

        public SqlCommand BuildCommand()
        {
            switch (RequestJob.Substring(6, 10))
            {
                case "0000000000": break;
                case "1000000000": break;
                case "1000000001": break;
                case "1000000002": break;
                case "2000000000":
                case "3000000000":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceKey", dwRequest["InstanceKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyDefType", dwRequest["KeyDefType"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKey", dwRequest["GoodsTypeKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsTypeKeyDefKey", dwRequest["GoodsTypeKeyDefKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@GoodsKey", dwRequest["GoodsKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@UGoodsKey", dwRequest["UGoodsKey"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TableID", dwRequest["TableID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TableName", dwRequest["TableName"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ShortName", dwRequest["ShortName"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@SubStatus", dwRequest["SubStatus"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyCondition", dwRequest["KeyCondition"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TableGroup", dwRequest["TableGroup"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TableClass", dwRequest["TableClass"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Status", dwRequest["Status"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@FrstUser", dwRequest["FrstUser"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@FrstDate", dwRequest["FrstDate"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LastUser", dwRequest["LastUser"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@LastDate", dwRequest["LastDate"].ToString()));

                    break;
                case "4000000000":
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    break;
            }
            return cmdSQL;

        }

    }
}

